var app;
jQuery(document).ready(function(){
	app = new Vue({
        el: '#app',
        data: {
            tableName : '',
            className : '',
            mode : 'javaBean',
            packagePath : 'com.westvalley.model',
            codeText : ''
        },
        methods: {
        	generatorCode : function(){
        		createCode();
        	},
        	generatorCodeRefresh : function(){
        		this.tableName = "";
        		this.className = "";
        		this.mode = "javaBean";
        		this.packagePath = "com.westvalley.model";
        		this.codeText = "";
        	}
        },
        created: function(){
        	
        }
    });
});

function createCode(){
	var url = "/mobile/plugin/westvalley/tools/generator/jsp/ajaxGeneratorCode.jsp";
	var data = {
		tableName : app.tableName,
		className : app.className,
		mode : app.mode,
		packagePath : app.packagePath
	};
	var o = ajaxText(url,data);
	app.codeText = myTrim(o);
}

function myTrim(x) {
    return x.replace(/(^\s*)|(\s*$)/g,''); 
}

/**
 * 异步提交
 * @param url
 * @param data
 * @returns json
 */
function ajaxJson(url, data) {
	var datas = "";
	jQuery.ajax({
		type : "POST",
		url : url,
		data : data,
		dataType : "json",
		async : false,
		success : function(data) {
			datas = data;
		},
		error: function(x,msg){
			alert(msg);
		}
	});
	return datas;
}

/**
 * 异步提交
 * @param url
 * @param data
 * @returns json
 */
function ajaxText(url, data) {
	var datas = "";
	jQuery.ajax({
		type : "POST",
		url : url,
		data : data,
		dataType : "text",
		async : false,
		success : function(data) {
			datas = data;
		},
		error: function(x,msg){
			alert(msg);
		}
	});
	return datas;
}